package com.rentong.wx.cust.controller;

import com.rentong.common.R;
import com.rentong.wx.cust.domain.CustAddressEntity;
import com.rentong.wx.cust.service.CustAddressService;
import com.rentong.wx.utils.WxApiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhangle
 * @email 459343178@qq.com
 * @date 2024-12-24 14:42:33
 */
@RestController
public class CustAddressController {

    @Autowired
    private CustAddressService custAddressService;


    /*
    27、查找服务地址簿信息
    */
    @GetMapping("custAddress/getAddress")
    public R getAddress(HttpServletRequest request, Integer pageNum, Integer pageSize) throws Exception {
        return R.success(custAddressService.getAddress(WxApiUtil.getCurrentCustId(request), pageNum, pageSize));
    }


    /*
    28、修改默认地址
     */
    @PutMapping("custAddress/updateMoRen")
    public R updateMoRen(Long addressId, HttpServletRequest request) throws Exception {
        Integer integer = custAddressService.updateMoRen(addressId, WxApiUtil.getCurrentCustId(request));
        if (integer > 0) {
            return R.success("操作成功");
        } else {
            return R.error("操作失败");
        }
    }

    /*
    29、新增地址信息
    */
    @PostMapping("custAddress/insertAddress")
    public R insertAddress(@RequestBody CustAddressEntity custAddressEntity, HttpServletRequest request) throws Exception {
        Integer integer = custAddressService.insertAddress(custAddressEntity, WxApiUtil.getCurrentCustId(request));
        if (integer > 0) {
            return R.success("操作成功");
        } else {
            return R.error("操作失败");
        }
    }


    /*
    30、删除地址信息
    */
    @DeleteMapping("custAddress/delAddress")
    public R delAddress(Long addressId) {
        Integer integer = custAddressService.delAddress(addressId);
        if (integer > 0) {
            return R.success("删除成功");
        } else {
            return R.error("删除失败");
        }
    }

    /*
    31、修改地址信息
    */
    @PutMapping("custAddress/updateAddress")
    public R updateAddress(@RequestBody CustAddressEntity custAddressEntity) {
        Integer integer = custAddressService.updateAddress(custAddressEntity);
        if (integer > 0) {
            return R.success("修改地址成功");
        } else {
            return R.error("修改地址删除失败");
        }
    }

    //129、查询用户默认地址
    @GetMapping("custAddress/getMorenAddress")
    public R getMorenAddress(HttpServletRequest request) throws Exception {
        return R.success(custAddressService.getMorenAddress(WxApiUtil.getCurrentCustId(request)));
    }


}
